using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Objects;
using System.Text;
using Acme.Northwind.EFDAL;
using nHydrate.EFCore.DataAccess;
using nHydrate.EFCore.EventArgs;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.Linq;

namespace Acme.Northwind.EFDAL.Entity
{
	/// <summary>
	/// The collection to hold 'Order' entities
	/// </summary>
	[System.CodeDom.Compiler.GeneratedCode("nHydrateModelGenerator", "5.0.1.100")]
	[EdmEntityTypeAttribute(NamespaceName="Acme.Northwind.EFDAL.Entity", Name="Order")]
	[Serializable()]
	[DataContractAttribute(IsReference = true)]
	[nHydrate.EFCore.Attributes.FieldNameConstantsAttribute(typeof(Acme.Northwind.EFDAL.Entity.Order.FieldNameConstants))]
	[System.ComponentModel.DataAnnotations.MetadataType(typeof(Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderMetadata))]
	[nHydrate.EFCore.Attributes.EntityMetadata("Order", false, true, true, true, "", true, false, false, "dbo")]
	public partial class Order : nHydrate.EFCore.DataAccess.NHEntityObject, nHydrate.EFCore.DataAccess.IBusinessObject, Acme.Northwind.EFDAL.IEntityWithContext, Acme.Northwind.EFDAL.Interfaces.Entity.IOrder, System.ICloneable, nHydrate.EFCore.DataAccess.IAuditable, System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IOrder>
	{
		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'Order' table.
		/// </summary>
		public enum FieldNameConstants
		{
			/// <summary>
			/// Field mapping for the 'CustomerID' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CustomerID' property")]
			CustomerID,
			/// <summary>
			/// Field mapping for the 'EmployeeID' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'EmployeeID' property")]
			EmployeeID,
			/// <summary>
			/// Field mapping for the 'Freight' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'Freight' property")]
			Freight,
			/// <summary>
			/// Field mapping for the 'OrderDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'OrderDate' property")]
			OrderDate,
			/// <summary>
			/// Field mapping for the 'OrderID' property
			/// </summary>
			[nHydrate.EFCore.Attributes.PrimaryKeyAttribute()]
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'OrderID' property")]
			OrderID,
			/// <summary>
			/// Field mapping for the 'RequiredDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'RequiredDate' property")]
			RequiredDate,
			/// <summary>
			/// Field mapping for the 'ShipAddress' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipAddress' property")]
			ShipAddress,
			/// <summary>
			/// Field mapping for the 'ShipCity' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipCity' property")]
			ShipCity,
			/// <summary>
			/// Field mapping for the 'ShipCountry' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipCountry' property")]
			ShipCountry,
			/// <summary>
			/// Field mapping for the 'ShipName' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipName' property")]
			ShipName,
			/// <summary>
			/// Field mapping for the 'ShippedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShippedDate' property")]
			ShippedDate,
			/// <summary>
			/// Field mapping for the 'ShipPostalCode' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipPostalCode' property")]
			ShipPostalCode,
			/// <summary>
			/// Field mapping for the 'ShipRegion' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipRegion' property")]
			ShipRegion,
			/// <summary>
			/// Field mapping for the 'ShipVia' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ShipVia' property")]
			ShipVia,
			/// <summary>
			/// Field mapping for the 'CreatedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedBy' property")]
			CreatedBy,
			/// <summary>
			/// Field mapping for the 'CreatedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'CreatedDate' property")]
			CreatedDate,
			/// <summary>
			/// Field mapping for the 'ModifiedBy' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedBy' property")]
			ModifiedBy,
			/// <summary>
			/// Field mapping for the 'ModifiedDate' property
			/// </summary>
			[System.ComponentModel.Description("Field mapping for the 'ModifiedDate' property")]
			ModifiedDate,
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Method called when an instance of this class is created
		/// </summary>
		partial void OnCreated();

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.Order class
		/// </summary>
		public Order()
		{
			_freight = 0M;
			this.OnCreated();
		}

		#endregion

		#region Properties

		/// <summary>
		/// The property that maps back to the database 'Orders.CustomerID' field
		/// </summary>
		/// <remarks>Field: [Orders].[CustomerID], Field Length: 5, Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("CustomerID")]
		public virtual string CustomerID
		{
			get { return _customerID; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.CustomerID))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.CustomerID", GetMaxLength(FieldNameConstants.CustomerID)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CustomerID");
				//this.OnCustomerIDChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CustomerID");
				_customerID = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("CustomerID");
				//this.OnCustomerIDChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.EmployeeID' field
		/// </summary>
		/// <remarks>Field: [Orders].[EmployeeID], Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("EmployeeID")]
		public virtual int? EmployeeID
		{
			get { return _employeeID; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<int?>(value, "EmployeeID");
				//this.OnEmployeeIDChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("EmployeeID");
				_employeeID = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("EmployeeID");
				//this.OnEmployeeIDChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.Freight' field
		/// </summary>
		/// <remarks>Field: [Orders].[Freight], Nullable, Default Value: 0</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Freight")]
		public virtual decimal? Freight
		{
			get { return _freight; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<decimal?>(value, "Freight");
				//this.OnFreightChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Freight");
				_freight = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("Freight");
				//this.OnFreightChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.OrderDate' field
		/// </summary>
		/// <remarks>Field: [Orders].[OrderDate], Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("OrderDate")]
		public virtual DateTime? OrderDate
		{
			get { return _orderDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'OrderDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'OrderDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "OrderDate");
				//this.OnOrderDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("OrderDate");
				_orderDate = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("OrderDate");
				//this.OnOrderDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.OrderID' field
		/// </summary>
		/// <remarks>Field: [Orders].[OrderID], Not Nullable, Primary Key, Unique, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("OrderID")]
		[System.ComponentModel.DataAnnotations.Key()]
		[System.ComponentModel.ReadOnly(true)]
		public virtual int OrderID
		{
			get { return _orderID; }
			set
			{
				ReportPropertyChanging("OrderID");
				_orderID = value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("OrderID");
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.RequiredDate' field
		/// </summary>
		/// <remarks>Field: [Orders].[RequiredDate], Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("RequiredDate")]
		public virtual DateTime? RequiredDate
		{
			get { return _requiredDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'RequiredDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'RequiredDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "RequiredDate");
				//this.OnRequiredDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("RequiredDate");
				_requiredDate = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("RequiredDate");
				//this.OnRequiredDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipAddress' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipAddress], Field Length: 60, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipAddress")]
		public virtual string ShipAddress
		{
			get { return _shipAddress; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipAddress))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipAddress", GetMaxLength(FieldNameConstants.ShipAddress)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipAddress");
				//this.OnShipAddressChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipAddress");
				_shipAddress = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipAddress");
				//this.OnShipAddressChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipCity' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipCity], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipCity")]
		public virtual string ShipCity
		{
			get { return _shipCity; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipCity))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipCity", GetMaxLength(FieldNameConstants.ShipCity)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipCity");
				//this.OnShipCityChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipCity");
				_shipCity = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipCity");
				//this.OnShipCityChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipCountry' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipCountry], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipCountry")]
		public virtual string ShipCountry
		{
			get { return _shipCountry; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipCountry))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipCountry", GetMaxLength(FieldNameConstants.ShipCountry)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipCountry");
				//this.OnShipCountryChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipCountry");
				_shipCountry = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipCountry");
				//this.OnShipCountryChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipName' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipName], Field Length: 40, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipName")]
		public virtual string ShipName
		{
			get { return _shipName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipName", GetMaxLength(FieldNameConstants.ShipName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipName");
				//this.OnShipNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipName");
				_shipName = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipName");
				//this.OnShipNameChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShippedDate' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShippedDate], Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShippedDate")]
		public virtual DateTime? ShippedDate
		{
			get { return _shippedDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'ShippedDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'ShippedDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "ShippedDate");
				//this.OnShippedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShippedDate");
				_shippedDate = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShippedDate");
				//this.OnShippedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipPostalCode' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipPostalCode], Field Length: 10, Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipPostalCode")]
		public virtual string ShipPostalCode
		{
			get { return _shipPostalCode; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipPostalCode))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipPostalCode", GetMaxLength(FieldNameConstants.ShipPostalCode)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipPostalCode");
				//this.OnShipPostalCodeChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipPostalCode");
				_shipPostalCode = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipPostalCode");
				//this.OnShipPostalCodeChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipRegion' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipRegion], Field Length: 15, Nullable</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipRegion")]
		public virtual string ShipRegion
		{
			get { return _shipRegion; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ShipRegion))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "Order.ShipRegion", GetMaxLength(FieldNameConstants.ShipRegion)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ShipRegion");
				//this.OnShipRegionChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipRegion");
				_shipRegion = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipRegion");
				//this.OnShipRegionChanged(eventArg);
			}
		}

		/// <summary>
		/// The property that maps back to the database 'Orders.ShipVia' field
		/// </summary>
		/// <remarks>Field: [Orders].[ShipVia], Nullable, Indexed</remarks>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShipVia")]
		public virtual int? ShipVia
		{
			get { return _shipVia; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<int?>(value, "ShipVia");
				//this.OnShipViaChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShipVia");
				_shipVia = eventArg.Value;
				_modifieddate = DateTime.Now;
				if ((this as IEntityWithContext).Context != null)
					_modifiedby = (this as IEntityWithContext).Context.ContextStartup.Modifer;
				ReportPropertyChanged("ShipVia");
				//this.OnShipViaChanged(eventArg);
			}
		}

		/// <summary>
		/// The audit field for the 'Created By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string CreatedBy
		{
			get { return _createdby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CreatedBy");
				//OnCreatedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedBy");
				_createdby = eventArg.Value;
				ReportPropertyChanged("CreatedBy");
				//OnCreatedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createdby' property
		/// </summary>
		protected string _createdby;

		/// <summary>
		/// The audit field for the 'Created Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? CreatedDate
		{
			get { return _createddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "CreatedDate");
				//OnCreatedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CreatedDate");
				_createddate = eventArg.Value;
				ReportPropertyChanged("CreatedDate");
				//OnCreatedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'createddate' property
		/// </summary>
		protected DateTime? _createddate;

		/// <summary>
		/// The audit field for the 'Modified By' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual string ModifiedBy
		{
			get { return _modifiedby; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ModifiedBy");
				//OnModifiedByChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedBy");
				_modifiedby = eventArg.Value;
				ReportPropertyChanged("ModifiedBy");
				//OnModifiedByChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifiedby' property
		/// </summary>
		protected string _modifiedby;

		/// <summary>
		/// The audit field for the 'Modified Date' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual DateTime? ModifiedDate
		{
			get { return _modifieddate; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "ModifiedDate");
				//OnModifiedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ModifiedDate");
				_modifieddate = eventArg.Value;
				ReportPropertyChanged("ModifiedDate");
				//OnModifiedDateChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'modifieddate' property
		/// </summary>
		protected DateTime? _modifieddate;

		/// <summary>
		/// The audit field for the 'Timestamp' parameter.
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		public virtual byte[] Timestamp
		{
			get { return _timestamp; }
			protected internal set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<byte[]>(value, "Timestamp");
				//OnTimestampChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Timestamp");
				_timestamp = eventArg.Value;
				ReportPropertyChanged("Timestamp");
				//OnTimestampChanged(eventArg);
			}
		}

		/// <summary>
		/// The internal reference variable for the 'timestamp' property
		/// </summary>
		protected byte[] _timestamp;

		#endregion

		#region Events

		/// <summary>
		/// The internal reference variable for the 'CustomerID' property
		/// </summary>
		protected string _customerID;

		/// <summary>
		/// The internal reference variable for the 'EmployeeID' property
		/// </summary>
		protected int? _employeeID;

		/// <summary>
		/// The internal reference variable for the 'Freight' property
		/// </summary>
		protected decimal? _freight;

		/// <summary>
		/// The internal reference variable for the 'OrderDate' property
		/// </summary>
		protected DateTime? _orderDate;

		/// <summary>
		/// The internal reference variable for the 'OrderID' property
		/// </summary>
		protected int _orderID;

		/// <summary>
		/// The internal reference variable for the 'RequiredDate' property
		/// </summary>
		protected DateTime? _requiredDate;

		/// <summary>
		/// The internal reference variable for the 'ShipAddress' property
		/// </summary>
		protected string _shipAddress;

		/// <summary>
		/// The internal reference variable for the 'ShipCity' property
		/// </summary>
		protected string _shipCity;

		/// <summary>
		/// The internal reference variable for the 'ShipCountry' property
		/// </summary>
		protected string _shipCountry;

		/// <summary>
		/// The internal reference variable for the 'ShipName' property
		/// </summary>
		protected string _shipName;

		/// <summary>
		/// The internal reference variable for the 'ShippedDate' property
		/// </summary>
		protected DateTime? _shippedDate;

		/// <summary>
		/// The internal reference variable for the 'ShipPostalCode' property
		/// </summary>
		protected string _shipPostalCode;

		/// <summary>
		/// The internal reference variable for the 'ShipRegion' property
		/// </summary>
		protected string _shipRegion;

		/// <summary>
		/// The internal reference variable for the 'ShipVia' property
		/// </summary>
		protected int? _shipVia;

		#endregion

		#region GetMaxLength

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.CustomerID:
					return 5;
				case FieldNameConstants.EmployeeID:
					return 0;
				case FieldNameConstants.Freight:
					return 0;
				case FieldNameConstants.OrderDate:
					return 0;
				case FieldNameConstants.OrderID:
					return 0;
				case FieldNameConstants.RequiredDate:
					return 0;
				case FieldNameConstants.ShipAddress:
					return 60;
				case FieldNameConstants.ShipCity:
					return 15;
				case FieldNameConstants.ShipCountry:
					return 15;
				case FieldNameConstants.ShipName:
					return 40;
				case FieldNameConstants.ShippedDate:
					return 0;
				case FieldNameConstants.ShipPostalCode:
					return 10;
				case FieldNameConstants.ShipRegion:
					return 15;
				case FieldNameConstants.ShipVia:
					return 0;
			}
			return 0;
		}

		int nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		#endregion

		#region GetFieldNameConstants

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldNameConstants()
		{
			return typeof(FieldNameConstants);
		}

		#endregion

		#region GetFieldType

		/// <summary>
		/// Gets the system type of a field on this object
		/// </summary>
		public static System.Type GetFieldType(FieldNameConstants field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.Order.FieldNameConstants'.");

			var array = Enum.GetValues(typeof(FieldNameConstants));
			switch ((FieldNameConstants)field)
			{
				case FieldNameConstants.CustomerID: return typeof(string);
				case FieldNameConstants.EmployeeID: return typeof(int?);
				case FieldNameConstants.Freight: return typeof(decimal?);
				case FieldNameConstants.OrderDate: return typeof(DateTime?);
				case FieldNameConstants.OrderID: return typeof(int);
				case FieldNameConstants.RequiredDate: return typeof(DateTime?);
				case FieldNameConstants.ShipAddress: return typeof(string);
				case FieldNameConstants.ShipCity: return typeof(string);
				case FieldNameConstants.ShipCountry: return typeof(string);
				case FieldNameConstants.ShipName: return typeof(string);
				case FieldNameConstants.ShippedDate: return typeof(DateTime?);
				case FieldNameConstants.ShipPostalCode: return typeof(string);
				case FieldNameConstants.ShipRegion: return typeof(string);
				case FieldNameConstants.ShipVia: return typeof(int?);
			}
			return null;
		}

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldType(Enum field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type 'Acme.Northwind.EFDAL.Entity.Order.FieldNameConstants'.");

			return GetFieldType((Acme.Northwind.EFDAL.Entity.Order.FieldNameConstants)field);
		}

		#endregion

		#region Get/Set Value

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field)
		{
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)this).GetValue(field, null);
		}

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field, object defaultValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		void nHydrate.EFCore.DataAccess.IBusinessObject.SetValue(System.Enum field, object newValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			this.SetValue((FieldNameConstants)field, newValue);
		}

		#endregion

		#region PrimaryKey

		/// <summary>
		/// Hold the primary key for this object
		/// </summary>
		protected nHydrate.EFCore.DataAccess.IPrimaryKey _primaryKey = null;
		nHydrate.EFCore.DataAccess.IPrimaryKey nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.PrimaryKey
		{
			get
			{
				if (_primaryKey == null) _primaryKey = new Acme.Northwind.EFDAL.Entity.OrderPrimaryKey(this.OrderID);
				return _primaryKey;
			}
		}

		#endregion

		#region IsParented

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (this.EntityState != System.Data.EntityState.Detached); }
		}

		#endregion

		#region Clone

		/// <summary>
		/// Creates a shallow copy of this object of all simple properties
		/// </summary>
		/// <returns></returns>
		public virtual object Clone()
		{
			var newItem = new Order();
			newItem._customerID = this._customerID;
			newItem._employeeID = this._employeeID;
			newItem._freight = this._freight;
			newItem._orderDate = this._orderDate;
			newItem._requiredDate = this._requiredDate;
			newItem._shipAddress = this._shipAddress;
			newItem._shipCity = this._shipCity;
			newItem._shipCountry = this._shipCountry;
			newItem._shipName = this._shipName;
			newItem._shippedDate = this._shippedDate;
			newItem._shipPostalCode = this._shipPostalCode;
			newItem._shipRegion = this._shipRegion;
			newItem._shipVia = this._shipVia;
			return newItem;
		}

		#endregion

		#region IsEquivalent

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(nHydrate.EFCore.DataAccess.INHEntityObject item)
		{
			if (item == null) return false;
			if (!(item is Acme.Northwind.EFDAL.Interfaces.Entity.IOrder)) return false;
			var o = item as Acme.Northwind.EFDAL.Interfaces.Entity.IOrder;
			return (
				o.CustomerID == this.CustomerID &&
				o.EmployeeID == this.EmployeeID &&
				o.Freight == this.Freight &&
				o.OrderDate == this.OrderDate &&
				o.OrderID == this.OrderID &&
				o.RequiredDate == this.RequiredDate &&
				o.ShipAddress == this.ShipAddress &&
				o.ShipCity == this.ShipCity &&
				o.ShipCountry == this.ShipCountry &&
				o.ShipName == this.ShipName &&
				o.ShippedDate == this.ShippedDate &&
				o.ShipPostalCode == this.ShipPostalCode &&
				o.ShipRegion == this.ShipRegion &&
				o.ShipVia == this.ShipVia
				);
		}

		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if (field == FieldNameConstants.CustomerID)
				return ((this.CustomerID == null) ? defaultValue : this.CustomerID);
			if (field == FieldNameConstants.EmployeeID)
				return ((this.EmployeeID == null) ? defaultValue : this.EmployeeID);
			if (field == FieldNameConstants.Freight)
				return ((this.Freight == null) ? defaultValue : this.Freight);
			if (field == FieldNameConstants.OrderDate)
				return ((this.OrderDate == null) ? defaultValue : this.OrderDate);
			if (field == FieldNameConstants.OrderID)
				return this.OrderID;
			if (field == FieldNameConstants.RequiredDate)
				return ((this.RequiredDate == null) ? defaultValue : this.RequiredDate);
			if (field == FieldNameConstants.ShipAddress)
				return ((this.ShipAddress == null) ? defaultValue : this.ShipAddress);
			if (field == FieldNameConstants.ShipCity)
				return ((this.ShipCity == null) ? defaultValue : this.ShipCity);
			if (field == FieldNameConstants.ShipCountry)
				return ((this.ShipCountry == null) ? defaultValue : this.ShipCountry);
			if (field == FieldNameConstants.ShipName)
				return ((this.ShipName == null) ? defaultValue : this.ShipName);
			if (field == FieldNameConstants.ShippedDate)
				return ((this.ShippedDate == null) ? defaultValue : this.ShippedDate);
			if (field == FieldNameConstants.ShipPostalCode)
				return ((this.ShipPostalCode == null) ? defaultValue : this.ShipPostalCode);
			if (field == FieldNameConstants.ShipRegion)
				return ((this.ShipRegion == null) ? defaultValue : this.ShipRegion);
			if (field == FieldNameConstants.ShipVia)
				return ((this.ShipVia == null) ? defaultValue : this.ShipVia);
			if (field == FieldNameConstants.CreatedBy)
				return ((this.CreatedBy == null) ? defaultValue : this.CreatedBy);
			if (field == FieldNameConstants.CreatedDate)
				return ((this.CreatedDate == null) ? defaultValue : this.CreatedDate);
			if (field == FieldNameConstants.ModifiedBy)
				return ((this.ModifiedBy == null) ? defaultValue : this.ModifiedBy);
			if (field == FieldNameConstants.ModifiedDate)
				return ((this.ModifiedDate == null) ? defaultValue : this.ModifiedDate);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region SetValue

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		public void SetValue(FieldNameConstants field, object newValue)
		{
			SetValue(field, newValue, false);
		}

		/// <summary>
		/// Assigns a value to a field on this object.
		/// </summary>
		/// <param name="field">The field to set</param>
		/// <param name="newValue">The new value to assign to the field</param>
		/// <param name="fixLength">Determines if the length should be truncated if too long. When false, an error will be raised if data is too large to be assigned to the field.</param>
		public void SetValue(FieldNameConstants field, object newValue, bool fixLength)
		{
			if (field == FieldNameConstants.CustomerID)
			{
				this.CustomerID = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.EmployeeID)
			{
				this.EmployeeID = GlobalValues.SetValueHelperIntNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.Freight)
			{
				if (newValue == null)
				{
					this.Freight = null;
				}
				else
				{
					if (newValue is string)
					{
						this.Freight = decimal.Parse((string)newValue);
					} else if (!(newValue is decimal?)) {
						this.Freight = decimal.Parse(newValue.ToString());
					}
					else if (newValue is nHydrate.EFCore.DataAccess.IBusinessObject)
					{
						throw new Exception("An invalid object of type 'IBusinessObject' was passed in. Perhaps a relationship was not enforced correctly.");
					}
					else
					this.Freight = (decimal?)newValue;
				}
			}
			else if (field == FieldNameConstants.OrderDate)
			{
				this.OrderDate = GlobalValues.SetValueHelperDateTimeNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.OrderID)
			{
				throw new Exception("Field '" + field.ToString() + "' is a primary key and cannot be set!");
			}
			else if (field == FieldNameConstants.RequiredDate)
			{
				this.RequiredDate = GlobalValues.SetValueHelperDateTimeNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.ShipAddress)
			{
				this.ShipAddress = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShipCity)
			{
				this.ShipCity = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShipCountry)
			{
				this.ShipCountry = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShipName)
			{
				this.ShipName = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShippedDate)
			{
				this.ShippedDate = GlobalValues.SetValueHelperDateTimeNullableInternal(newValue);
			}
			else if (field == FieldNameConstants.ShipPostalCode)
			{
				this.ShipPostalCode = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShipRegion)
			{
				this.ShipRegion = GlobalValues.SetValueHelperInternal((string)newValue, fixLength, GetMaxLength(field));
			}
			else if (field == FieldNameConstants.ShipVia)
			{
				this.ShipVia = GlobalValues.SetValueHelperIntNullableInternal(newValue);
			}
			else
				throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		#endregion

		#region Navigation Properties

		/// <summary>
		/// The back navigation definition for walking [Order]->[OrderDetail]
		/// Relationship Links: 
		/// [Orders.OrderID = Order Details.OrderID] (Required)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrderDetailList")]
		public virtual EntityCollection<Acme.Northwind.EFDAL.Entity.OrderDetail> Order_details_ordersOrderDetailList
		{
			get
			{
				//Eager load
				var retval = ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Acme.Northwind.EFDAL.Entity.OrderDetail>("Acme.Northwind.EFDAL.Entity.FK_Order_details_orders_OrderDetail_Order", "Order_details_ordersOrderDetailList");
				if (!retval.IsLoaded  && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval;
			}
		}

		#region IOrder Interface

		System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail> Acme.Northwind.EFDAL.Interfaces.Entity.IOrder.Order_details_ordersOrderDetailList
		{
			get { return (System.Collections.Generic.ICollection<Acme.Northwind.EFDAL.Interfaces.Entity.IOrderDetail>)(System.Collections.Generic.ICollection<OrderDetail>)this.Order_details_ordersOrderDetailList; }
		}

		#endregion

		/// <summary>
		/// The navigation definition for walking [Order]->[Customer]
		/// Relationship Links: 
		/// [Customers.CustomerID = Orders.CustomerID] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK__Order_Customer", "Customer")]
		public virtual Customer Customer
		{
			get
			{
				var retval = CustomerReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("Acme.Northwind.EFDAL.Entity.FK__Order_Customer", "Customer").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Customer->Order
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Customer> CustomerReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("Acme.Northwind.EFDAL.Entity.FK__Order_Customer", "Customer"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Customer>("Acme.Northwind.EFDAL.Entity.FK__Order_Customer", "Customer", value);
			}
		}

		#region IOrder Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.ICustomer Acme.Northwind.EFDAL.Interfaces.Entity.IOrder.Customer
		{
			get { return this.Customer; }
			set { this.Customer = (Acme.Northwind.EFDAL.Entity.Customer)value; }
		}

		#endregion

		/// <summary>
		/// The navigation definition for walking [Order]->[Employee]
		/// Relationship Links: 
		/// [Employees.EmployeeID = Orders.EmployeeID] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK__Order_Employee", "Employee")]
		public virtual Employee Employee
		{
			get
			{
				var retval = EmployeeReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK__Order_Employee", "Employee").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Employee->Order
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Employee> EmployeeReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK__Order_Employee", "Employee"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Employee>("Acme.Northwind.EFDAL.Entity.FK__Order_Employee", "Employee", value);
			}
		}

		#region IOrder Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.IEmployee Acme.Northwind.EFDAL.Interfaces.Entity.IOrder.Employee
		{
			get { return this.Employee; }
			set { this.Employee = (Acme.Northwind.EFDAL.Entity.Employee)value; }
		}

		#endregion

		/// <summary>
		/// The navigation definition for walking [Order]->[Shipper]
		/// Relationship Links: 
		/// [Shippers.ShipperID = Orders.ShipVia] (Optional)
		/// </summary>
		[XmlIgnoreAttribute()]
		[SoapIgnoreAttribute()]
		[EdmRelationshipNavigationPropertyAttribute("Acme.Northwind.EFDAL.Entity", "FK__Order_Shipper", "Shipper")]
		public virtual Shipper Shipper
		{
			get
			{
				var retval = ShipperReference;
				if (!retval.IsLoaded && this.EntityState != System.Data.EntityState.Added && this.EntityState != System.Data.EntityState.Detached)
				{
					retval.Load();
				}
				return retval.Value;
			}
			set { ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Shipper>("Acme.Northwind.EFDAL.Entity.FK__Order_Shipper", "Shipper").Value = value; }
		}

		/// <summary>
		/// The navigation reference definition for walking Shipper->Order
		/// </summary>
		[BrowsableAttribute(false)]
		protected virtual EntityReference<Shipper> ShipperReference
		{
			get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Shipper>("Acme.Northwind.EFDAL.Entity.FK__Order_Shipper", "Shipper"); }
			set
			{
				if ((value != null))
					((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Shipper>("Acme.Northwind.EFDAL.Entity.FK__Order_Shipper", "Shipper", value);
			}
		}

		#region IOrder Interface

		Acme.Northwind.EFDAL.Interfaces.Entity.IShipper Acme.Northwind.EFDAL.Interfaces.Entity.IOrder.Shipper
		{
			get { return this.Shipper; }
			set { this.Shipper = (Acme.Northwind.EFDAL.Entity.Shipper)value; }
		}

		#endregion

		#endregion

		#region Static SQL Methods

		internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
		{
			alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
			switch (alias.ToLower())
			{
				case "customerid": return "customerid";
				case "employeeid": return "employeeid";
				case "freight": return "freight";
				case "orderdate": return "orderdate";
				case "orderid": return "orderid";
				case "requireddate": return "requireddate";
				case "shipaddress": return "shipaddress";
				case "shipcity": return "shipcity";
				case "shipcountry": return "shipcountry";
				case "shipname": return "shipname";
				case "shippeddate": return "shippeddate";
				case "shippostalcode": return "shippostalcode";
				case "shipregion": return "shipregion";
				case "shipvia": return "shipvia";
				case "createddate": return "createddate";
				case "createdby": return "createdby";
				case "modifieddate": return "modifieddate";
				case "modifiedby": return "modifiedby";
				case "timestamp": return "timestamp";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldAliasSqlMapping(string alias)
		{
			switch (alias.ToLower())
			{
				case "customerid": return "Orders";
				case "employeeid": return "Orders";
				case "freight": return "Orders";
				case "orderdate": return "Orders";
				case "orderid": return "Orders";
				case "requireddate": return "Orders";
				case "shipaddress": return "Orders";
				case "shipcity": return "Orders";
				case "shipcountry": return "Orders";
				case "shipname": return "Orders";
				case "shippeddate": return "Orders";
				case "shippostalcode": return "Orders";
				case "shipregion": return "Orders";
				case "shipvia": return "Orders";
				case "createdby": return "Orders";
				case "createddate": return "Orders";
				case "modifiedby": return "Orders";
				case "modifieddate": return "Orders";
				case "timestamp": return "Orders";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetTableFromFieldNameSqlMapping(string field)
		{
			switch (field.ToLower())
			{
				case "customerid": return "Orders";
				case "employeeid": return "Orders";
				case "freight": return "Orders";
				case "orderdate": return "Orders";
				case "orderid": return "Orders";
				case "requireddate": return "Orders";
				case "shipaddress": return "Orders";
				case "shipcity": return "Orders";
				case "shipcountry": return "Orders";
				case "shipname": return "Orders";
				case "shippeddate": return "Orders";
				case "shippostalcode": return "Orders";
				case "shipregion": return "Orders";
				case "shipvia": return "Orders";
				case "createdby": return "Orders";
				case "createddate": return "Orders";
				case "modifiedby": return "Orders";
				case "modifieddate": return "Orders";
				case "timestamp": return "Orders";
				default: throw new Exception("The select clause is not valid.");
			}
		}

		internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
		{
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[customerid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[customerid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[employeeid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[employeeid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[freight\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[freight]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[orderdate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[orderdate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[orderid\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[orderid]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[requireddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[requireddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipaddress\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipaddress]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipcity\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipcity]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipcountry\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipcountry]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipname\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipname]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shippeddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shippeddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shippostalcode\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shippostalcode]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipregion\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipregion]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[shipvia\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[shipvia]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createdby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[createdby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[createddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifiedby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[modifiedby]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifieddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[modifieddate]", RegexOptions.IgnoreCase);
			sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[timestamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "Orders") + "].[timestamp]", RegexOptions.IgnoreCase);
			return sql;
		}

		#endregion

		#region DeleteData

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where)
		{
			return DeleteData(where, new nHydrate.EFCore.DataAccess.QueryOptimizer());
		}

		/// <summary>
		/// Delete all records that match a where condition
		/// </summary>
		/// <param name="where">The expression that determines the records deleted</param>
		/// <param name="optimizer">The optimization object to use for running queries</param>
		/// <returns>The number of rows deleted</returns>
		public static int DeleteData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, nHydrate.EFCore.DataAccess.QueryOptimizer optimizer)
		{
			if (optimizer == null) throw new Exception("The 'optimizer' parameter cannot be null.");

			var dc = new DataContext(Acme.Northwind.EFDAL.DBHelper.GetConnection());
			var  template = dc.GetTable<Acme.Northwind.EFDAL.OrderQuery>();
			var cmd = nHydrate.EFCore.DataAccess.BusinessEntityQuery.GetCommand<Acme.Northwind.EFDAL.OrderQuery>(dc, template, where);
			cmd.CommandTimeout = 30;

			var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table);
			string sql = "SELECT [t0].[OrderID] INTO #t\r\n";
			sql += parser.GetFromClause(optimizer) + "\r\n";
			sql += parser.GetWhereClause();
			sql += "\r\n";

			var noLock = string.Empty;
			noLock = (optimizer.NoLocking ? "WITH (NOLOCK) " : string.Empty);
			sql += "DELETE [Orders] FROM [dbo].[Orders] " + noLock + "INNER JOIN #t ON [dbo].[Orders].[OrderID] = #t.[OrderID]\r\n";
			sql += ";select @@rowcount";
			cmd.CommandText = sql;
			dc.Connection.Open();
			var startTime = DateTime.Now;
			object p = cmd.ExecuteScalar();
			var endTime = DateTime.Now;
			optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
			dc.Connection.Close();
			return (int)p;
		}

		#endregion

		#region UpdateData

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, int>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, int newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, int>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, int?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, int? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, int?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, Single>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, Single newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, Single>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, Single?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, Single? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, Single?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, decimal>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, decimal newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, decimal>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, decimal?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, decimal? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, decimal?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, double>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, double newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, double>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, double?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, double? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, double?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, short>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, short newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, short>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, short?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, short? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, short?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, string>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, string newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, string>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, DateTime>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, DateTime newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, DateTime>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, DateTime?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, DateTime? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, DateTime?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, bool newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, bool>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, bool? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, bool?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, Guid>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, Guid newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, Guid>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, Guid?>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, Guid? newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, Guid?>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		/// <summary>
		/// Update the specified field that matches the Where expression with the new data value
		/// </summary>
		/// <param name="select">The field to update</param>
		/// <param name="where">The expression that determines the records selected</param>
		/// <param name="newValue">The new value to set the specified field in all matching records</param>
		/// <returns>The number of records affected</returns>
		public static int UpdateData(Expression<Func<Acme.Northwind.EFDAL.OrderQuery, byte[]>> select, Expression<Func<Acme.Northwind.EFDAL.OrderQuery, bool>> where, byte[] newValue)
		{
			return BusinessObjectQuery<Acme.Northwind.EFDAL.Entity.Order, Acme.Northwind.EFDAL.OrderQuery, byte[]>.UpdateData(select, where, newValue, "Orders", GetDatabaseFieldName, true);
		}

		#endregion

		#region GetDatabaseFieldName

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(Order.FieldNameConstants field)
		{
			return GetDatabaseFieldName(field.ToString());
		}

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(string field)
		{
			switch (field)
			{
				case "CustomerID": return "CustomerID";
				case "EmployeeID": return "EmployeeID";
				case "Freight": return "Freight";
				case "OrderDate": return "OrderDate";
				case "OrderID": return "OrderID";
				case "RequiredDate": return "RequiredDate";
				case "ShipAddress": return "ShipAddress";
				case "ShipCity": return "ShipCity";
				case "ShipCountry": return "ShipCountry";
				case "ShipName": return "ShipName";
				case "ShippedDate": return "ShippedDate";
				case "ShipPostalCode": return "ShipPostalCode";
				case "ShipRegion": return "ShipRegion";
				case "ShipVia": return "ShipVia";
				case "CreatedBy": return "CreatedBy";
				case "CreatedDate": return "CreatedDate";
				case "ModifiedBy": return "ModifiedBy";
				case "ModifiedDate": return "ModifiedDate";
				case "Timestamp": return "Timestamp";
			}
			return string.Empty;
		}

		#endregion

		#region Context

		NorthwindEntities IEntityWithContext.Context
		{
			get { return _internalContext; }
			set { _internalContext = value; }
		}
		private NorthwindEntities _internalContext = null;

		#endregion

		#region Auditing
		string nHydrate.EFCore.DataAccess.IAuditable.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsCreateAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsModifyAuditImplemented
		{
			get { return true; }
		}

		bool nHydrate.EFCore.DataAccess.IAuditable.IsTimestampAuditImplemented
		{
			get { return true; }
		}

		string nHydrate.EFCore.DataAccess.IAuditable.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		System.DateTime? nHydrate.EFCore.DataAccess.IAuditable.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		byte[] nHydrate.EFCore.DataAccess.IAuditable.TimeStamp
		{
			get { return this.Timestamp; }
		}

		internal virtual void ResetModifiedBy(string modifier)
		{
			if (this.ModifiedBy != modifier)
				this.ModifiedBy = modifier;
		}

		internal virtual void ResetCreatedBy(string modifier)
		{
			if (this.CreatedBy != modifier)
				this.CreatedBy = modifier;
			this.ResetModifiedBy(modifier);
		}
		#endregion

		#region Static Methods

		/// <summary>
		/// Select a single element by its primary key value
		/// </summary>
		public static Acme.Northwind.EFDAL.Entity.Order SelectByPK(int orderID)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Order.FirstOrDefault(x => x.OrderID == orderID);
			}
		}

		/// <summary>
		/// Returns a list of distinct values based on a predicate
		/// </summary>
		public static IEnumerable<T> GetDistinct<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, T>> select, System.Linq.Expressions.Expression<Func<Order, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Order.Where(predicate).Select(select).Distinct().ToList();
			}
		}

		/// <summary>
		/// Returns a count of items based on a predicate
		/// </summary>
		public static int GetCount(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Order.Count(predicate);
			}
		}

		/// <summary>
		/// Returns a maximum property value of based on a predicate
		/// </summary>
		public static T GetMax<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Order.Where(predicate).Select(select).Max();
			}
		}

		/// <summary>
		/// Returns a minimum property value of based on a predicate
		/// </summary>
		public static T GetMin<T>(System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, T>> select, System.Linq.Expressions.Expression<Func<Acme.Northwind.EFDAL.Entity.Order, bool>> predicate)
		{
			using (var context = new Acme.Northwind.EFDAL.NorthwindEntities())
			{
				return context.Order.Where(predicate).Select(select).Min();
			}
		}

		/// <summary>
		/// Creates and returns a metadata object for an entity type
		/// </summary>
		/// <returns>A metadata object for the entity types in this assembly</returns>
		public static Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderMetadata GetMetadata()
		{
			var a = typeof(Order).GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.MetadataTypeAttribute), true).FirstOrDefault();
			if (a == null) return null;
			var t = ((System.ComponentModel.DataAnnotations.MetadataTypeAttribute)a).MetadataClassType;
			if (t == null) return null;
			return Activator.CreateInstance(t) as nHydrate.EFCore.DataAccess.IMetadata as Acme.Northwind.EFDAL.Interfaces.Entity.Metadata.OrderMetadata;
		}

		#endregion

		#region Equals
		bool System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.IOrder>.Equals(Acme.Northwind.EFDAL.Interfaces.Entity.IOrder other)
		{
			return this.IsEquivalent(other);
		}
		#endregion

		#region IDataErrorInfo
		/// <summary>
		/// 
		/// </summary>
		string System.ComponentModel.IDataErrorInfo.Error
		{
			get { return this.GetObjectDataErrorInfo(); }
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="columnName"></param>
		/// <returns></returns>
		string System.ComponentModel.IDataErrorInfo.this[string columnName]
		{
			get
			{
				if (string.IsNullOrEmpty(columnName))
					return string.Empty;

				var retval = GetObjectPropertyDataErrorInfo(columnName);
				if (string.IsNullOrEmpty(retval))
				{
					switch (columnName.ToLower())
					{
						default:
							break;
					}
				}
				return retval;
			}
		}
		#endregion

	}

	partial class Order : nHydrate.EFCore.DataAccess.ICreatedAudit, nHydrate.EFCore.DataAccess.IModifiedAudit, nHydrate.EFCore.DataAccess.IConcurrencyAudit
	{
		#region ICreatedAudit Members

		string ICreatedAudit.CreatedBy
		{
			get { return this.CreatedBy; }
		}

		DateTime? ICreatedAudit.CreatedDate
		{
			get { return this.CreatedDate; }
		}

		#endregion

		#region IModifiedAudit Members

		string IModifiedAudit.ModifiedBy
		{
			get { return this.ModifiedBy; }
		}

		DateTime? IModifiedAudit.ModifiedDate
		{
			get { return this.ModifiedDate; }
		}

		#endregion

		#region IConcurrencyAudit Members

		byte[] IConcurrencyAudit.TimeStamp
		{
			get { return this.Timestamp; }
		}

		#endregion

	}

}

